<script setup>
import {useRoute} from 'vue-router'
import {onMounted} from 'vue'
import {useDetailStore} from '/src/store/modules/HospitalDetail.js'
import router from "@/router/index.js";
import {Platform} from "@element-plus/icons-vue";

const route = useRoute()
// 组件挂载通知pinia仓库发请求获取医院详情存储到仓库中
const detailStore = useDetailStore()
onMounted(() => {
  // 获取医院详情数据
  detailStore.getHospitalDetail(route.query.hoscode);
  // 获取医院科室列表数据
  detailStore.getHospitalDepartment(route.query.hoscode);
})

const handleSelect = (index) => {
  const hoscode = route.query.hoscode;
  router.push({ path: index, query: { hoscode } })
}

const menuItems =[
  { index: '/hospital/register', icon: 'Calendar', title: '预约挂号' },
  { index: '/hospital/detail', icon: 'Document', title: '医院详情' },
  { index: '/hospital/notice', icon: 'Bell', title: '预约须知' },
  { index: '/hospital/stop', icon: 'InfoFilled', title: '停诊信息' },
  { index: '/hospital/search', icon: 'Search', title: '查询/取消' },
]

</script>

<template>
  <div class="hospital-detail">
    <!-- 左侧菜单 -->
    <div class="left-menu">
      <div class="logo">>>
        <el-icon>
          <Platform />
        </el-icon>&nbsp;医院信息
      </div>
      <el-menu
          :default-active="route.path"
          class="el-menu-vertical-demo"
          router
          @select="handleSelect"
      >
        <el-menu-item v-for="(item, index) in menuItems" :key="index" :index="item.index">
          <el-icon>
            <component :is="item.icon"/>
          </el-icon>
          <span>{{ item.title }}</span>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 右侧内容 -->
    <div class="right-content">
      <router-view></router-view>
    </div>
  </div>
</template>

<style scoped lang="scss">
.hospital-detail {
  display: flex;
  width: 100%;
  height: 100%;

  .left-menu {
    flex: 2;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;

    .logo {
      color: #7f7f7f;
      font-size: 18px;
      font-weight: bold;
      margin-bottom: 10px;
    }

    .el-menu-item span {
      margin-left: 5px;
      font-size: 16px;
      font-weight: bold;
    }
  }

  .right-content {
    flex: 8;
    background-color: #fff;
    padding: 10px;
    display: flex;
  }
}

</style>